package com.longe.nio.channel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class FileChannelTest003 {

    public static void main(String[] args) throws Exception {
        //定义一个文件输入流
        FileInputStream fis = new FileInputStream("demo1.txt");
        //获取channel
        FileChannel fileChannelIn = fis.getChannel();

        //定义一个文件输出流
        FileOutputStream fos = new FileOutputStream("demo3.txt");
        //获取channel
        FileChannel fileChannelOut = fos.getChannel();

        //transferFrom对容量有限制,使用的时候注意
        fileChannelOut.transferFrom(fileChannelIn, 0, fileChannelIn.size());

        //关闭通道和流
        fileChannelIn.close();
        fis.close();
        fileChannelOut.close();
        fos.close();
    }
}
